var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var app = getApp();

Page({
  data: {
    bannerInfo: {
      'imgUrl': 'https://wh.nazhiyun.com/home/youtao/imgs/grouponMore2x.png',
      'name': ''
    },
    goodsList: [],
    page: 1,
    size: 10,
    totalPages: 1
  },
  getGoodsList: function () {
    var that = this;
    util.request(api.GroupOnList, {
      page: that.data.page,
      size: 10
    }).then(function(res) {
        if (res.errno === 0) {
          that.setData({
            goodsList: that.data.goodsList.concat(res.data.data),
            totalPages: res.data.totalPages
          });
        }
      });

  },
  onLoad: function (options) {
    this.getGoodsList();
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onReachBottom: function () {
    if (this.data.totalPages > this.data.page) {
      this.setData({
        page: this.data.page + 1
      });
    } else {
      wx.showToast({
        title: '已经到底了!',
        icon: 'none',
        duration: 2000
      });
      return false;
    }
    this.getGoodsList();
  }
})